package cn.itcast.bos.service.base.imp;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.dao.base.CourierDao;
import cn.itcast.bos.domain.base.Courier;
import cn.itcast.bos.service.base.CourierService;

@Service
@Transactional
public class CourierServiceImp implements CourierService {

	@Autowired
	private CourierDao courierDao;

	/***
	 * 快递员保存
	 */
	@Override
	@RequiresPermissions("courier_add")
	public void save(Courier courier) {
		courierDao.save(courier);
	}

	/***
	 * 快递员分页
	 */
	@Override
	public Page<Courier> findAll(Specification<Courier> spec, Pageable pageable) {

		return courierDao.findAll(spec, pageable);
	}

	/***
	 * 快递员删除
	 */
	@Override
	public void delCourier(String[] dd) {

		// 遍历数据进行持久操作
		for (String ids : dd) {
			int id = Integer.parseInt(ids);
			courierDao.delCourier(id);
		}
	}

	@Override
	public void restoreBatch(String[] split) {
		// 遍历数据进行持久操作
		for (String ids : split) {
			int id = Integer.parseInt(ids);
			courierDao.restoreBatch(id);
		}
	}

	@Override
	public Courier findById(Integer id) {
		return courierDao.findOne(id);
	}

	@Override
	public List<Courier> findNoFixedAreaCourier() {
		return courierDao.findNoFixedAreaCourier();
	}

}
